```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解线程池状态流转</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .state-card {
            border-left: 4px solid;
            transition: all 0.3s ease;
        }
        .state-card:hover {
            transform: translateX(5px);
        }
        .text-gradient {
            background: linear-gradient(90deg, #3b82f6, #10b981);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 0.8;
            margin-right: 0.5rem;
            margin-top: 0.3rem;
            color: #3b82f6;
            font-weight: 700;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 2rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6">深入理解<span class="text-yellow-300">线程池状态流转</span></h1>
                <p class="text-xl md:text-2xl mb-8 max-w-3xl opacity-90">探索Java ThreadPoolExecutor的生命周期与状态转换机制</p>
                <div class="flex space-x-4">
                    <div class="px-6 py-3 bg-white text-blue-600 font-semibold rounded-full hover:bg-blue-50 transition duration-300">
                        <i class="fas fa-book-open mr-2"></i>核心概念
                    </div>
                    <div class="px-6 py-3 bg-blue-700 text-white font-semibold rounded-full hover:bg-blue-800 transition duration-300">
                        <i class="fas fa-project-diagram mr-2"></i>状态流转
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section class="py-16">
        <div class="container mx-auto px-6 max-w-5xl">
            <!-- Introduction -->
            <div class="bg-white rounded-xl shadow-md p-8 mb-12 card-hover">
                <p class="text-lg drop-cap">线程池在运行过程中会经历不同的状态，这些状态反映了线程池的当前工作情况和任务处理进度。Java的ThreadPoolExecutor提供了完善的状态管理机制，理解这些状态及其转换关系对于编写健壮的多线程应用至关重要。</p>
            </div>

            <!-- Thread Pool States Section -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                    <i class="fas fa-tasks mr-4 text-blue-500"></i>
                    <span class="text-gradient">线程池状态详解</span>
                </h2>
                
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                    <!-- RUNNING -->
                    <div class="state-card border-blue-500 bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                                <i class="fas fa-play text-blue-500 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">RUNNING</h3>
                        </div>
                        <p class="text-gray-600">线程池正在运行，能够接受新任务并处理队列中的任务。</p>
                    </div>
                    
                    <!-- SHUTDOWN -->
                    <div class="state-card border-yellow-500 bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-yellow-100 flex items-center justify-center mr-4">
                                <i class="fas fa-pause text-yellow-500 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">SHUTDOWN</h3>
                        </div>
                        <p class="text-gray-600">线程池正在关闭，不再接受新任务，但会继续处理队列中的任务。</p>
                    </div>
                    
                    <!-- STOP -->
                    <div class="state-card border-red-500 bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-red-100 flex items-center justify-center mr-4">
                                <i class="fas fa-stop text-red-500 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">STOP</h3>
                        </div>
                        <p class="text-gray-600">线程池完全停止，不再接受新任务，也不会处理队列中的任务，并且会中断所有正在执行的线程。</p>
                    </div>
                    
                    <!-- TIDYING -->
                    <div class="state-card border-purple-500 bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                                <i class="fas fa-broom text-purple-500 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">TIDYING</h3>
                        </div>
                        <p class="text-gray-600">线程池的所有任务已经完成，线程池正在进行清理工作（如资源释放）。</p>
                    </div>
                    
                    <!-- TERMINATED -->
                    <div class="state-card border-green-500 bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center mr-4">
                                <i class="fas fa-check-circle text-green-500 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">TERMINATED</h3>
                        </div>
                        <p class="text-gray-600">线程池已经完全终止，所有的清理工作完成，线程池进入终止状态。</p>
                    </div>
                </div>
            </div>

            <!-- State Transitions -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                    <i class="fas fa-random mr-4 text-blue-500"></i>
                    <span class="text-gradient">状态流转路径</span>
                </h2>
                
                <div class="bg-white rounded-xl shadow-md p-8 mb-8 card-hover">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">主要状态转换</h3>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
                        <!-- RUNNING to SHUTDOWN -->
                        <div class="bg-blue-50 p-6 rounded-lg border-l-4 border-blue-400">
                            <h4 class="font-bold text-lg mb-3 text-blue-800 flex items-center">
                                <i class="fas fa-arrow-right mr-2"></i>从 RUNNING 到 SHUTDOWN
                            </h4>
                            <p class="text-gray-700 mb-2"><span class="font-semibold">触发条件：</span>调用 <code class="bg-gray-100 px-2 py-1 rounded">shutdown()</code> 方法。</p>
                            <p class="text-gray-700"><span class="font-semibold">描述：</span>线程池进入 SHUTDOWN 状态后，不再接受新的任务，但会继续处理队列中的任务。已经提交的任务会被执行完成。</p>
                        </div>
                        
                        <!-- RUNNING to STOP -->
                        <div class="bg-red-50 p-6 rounded-lg border-l-4 border-red-400">
                            <h4 class="font-bold text-lg mb-3 text-red-800 flex items-center">
                                <i class="fas fa-arrow-right mr-2"></i>从 RUNNING 到 STOP
                            </h4>
                            <p class="text-gray-700 mb-2"><span class="font-semibold">触发条件：</span>调用 <code class="bg-gray-100 px-2 py-1 rounded">shutdownNow()</code> 方法。</p>
                            <p class="text-gray-700"><span class="font-semibold">描述：</span>线程池进入 STOP 状态后，不再接受新任务，并且会尝试中断正在执行的任务，清空队列中的任务。</p>
                        </div>
                    </div>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <!-- SHUTDOWN to TIDYING -->
                        <div class="bg-yellow-50 p-6 rounded-lg border-l-4 border-yellow-400">
                            <h4 class="font-bold text-lg mb-3 text-yellow-800 flex items-center">
                                <i class="fas fa-arrow-right mr-2"></i>从 SHUTDOWN 到 TIDYING
                            </h4>
                            <p class="text-gray-700 mb-2"><span class="font-semibold">触发条件：</span>当队列中的任务全部执行完成，且线程池中的所有线程已经退出。</p>
                            <p class="text-gray-700"><span class="font-semibold">描述：</span>线程池准备进行清理工作，此时已经不再有活动线程。</p>
                        </div>
                        
                        <!-- STOP to TIDYING -->
                        <div class="bg-purple-50 p-6 rounded-lg border-l-4 border-purple-400">
                            <h4 class="font-bold text-lg mb-3 text-purple-800 flex items-center">
                                <i class="fas fa-arrow-right mr-2"></i>从 STOP 到 TIDYING
                            </h4>
                            <p class="text-gray-700 mb-2"><span class="font-semibold">触发条件：</span>所有任务（包括正在执行的任务）被中断或完成，线程池中的所有线程被中断，队列被清空。</p>
                            <p class="text-gray-700"><span class="font-semibold">描述：</span>线程池准备进行清理工作，但此时仍处于 STOP 状态。</p>
                        </div>
                    </div>
                    
                    <div class="mt-8">
                        <div class="bg-green-50 p-6 rounded-lg border-l-4 border-green-400 max-w-2xl mx-auto">
                            <h4 class="font-bold text-lg mb-3 text-green-800 flex items-center justify-center">
                                <i class="fas fa-arrow-right mr-2"></i>从 TIDYING 到 TERMINATED
                            </h4>
                            <p class="text-gray-700 mb-2 text-center"><span class="font-semibold">触发条件：</span>线程池中的清理工作完成。</p>
                            <p class="text-gray-700 text-center"><span class="font-semibold">描述：</span>线程池已经完全终止，所有资源已被释放。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- State Diagram -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                    <i class="fas fa-project-diagram mr-4 text-blue-500"></i>
                    <span class="text-gradient">状态流转示意图</span>
                </h2>
                
                <div class="mermaid">
                    stateDiagram-v2
                        [*] --> RUNNING
                        RUNNING --> SHUTDOWN: shutdown()
                        RUNNING --> STOP: shutdownNow()
                        SHUTDOWN --> TIDYING: 任务完成且线程退出
                        STOP --> TIDYING: 所有线程中断完成
                        TIDYING --> TERMINATED: terminated()
                        TERMINATED --> [*]
                        
                        state RUNNING {
                            [*] --> 接受新任务
                            接受新任务 --> 处理队列任务
                        }
                        
                        state SHUTDOWN {
                            [*] --> 拒绝新任务
                            拒绝新任务 --> 处理队列任务
                        }
                        
                        state STOP {
                            [*] --> 拒绝新任务
                            拒绝新任务 --> 中断所有线程
                        }
                </div>
            </div>

            <!-- Detailed Process -->
            <div>
                <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                    <i class="fas fa-list-ol mr-4 text-blue-500"></i>
                    <span class="text-gradient">状态流转的详细过程</span>
                </h2>
                
                <div class="space-y-6">
                    <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-blue-600">RUNNING 到 SHUTDOWN</h3>
                        <p class="text-gray-700">通过调用 <code class="bg-gray-100 px-2 py-1 rounded">shutdown()</code> 方法，线程池会首先将状态标记为 SHUTDOWN，不再接受新的任务，但会继续处理已经提交的任务。这是优雅关闭线程池的标准方式，适用于需要确保所有已提交任务都被执行完毕的场景。</p>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-yellow-600">SHUTDOWN 到 TIDYING</h3>
                        <p class="text-gray-700">当线程池中的任务完成（包括工作队列中的所有任务和正在执行的任务），并且所有工作线程都已退出（包括核心线程和非核心线程），线程池将进入 TIDYING 状态。这个状态表示线程池已经完成了所有任务执行，正准备进行清理工作。</p>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-purple-600">TIDYING 到 TERMINATED</h3>
                        <p class="text-gray-700">在 TIDYING 状态下，线程池会调用 <code class="bg-gray-100 px-2 py-1 rounded">terminated()</code> 钩子方法（子类可以重写此方法以实现自定义清理逻辑）。清理工作完成后，线程池会进入 TERMINATED 状态，标志着线程池生命周期的完全结束。</p>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-red-600">RUNNING 到 STOP</h3>
                        <p class="text-gray-700">通过调用 <code class="bg-gray-100 px-2 py-1 rounded">shutdownNow()</code> 方法，线程池会尝试立即停止：首先将状态标记为 STOP，然后尝试中断所有正在执行的任务（通过调用线程的 <code class="bg-gray-100 px-2 py-1 rounded">interrupt()</code> 方法），并清空工作队列。这是强制关闭线程池的方式，适用于需要立即停止所有任务的场景。</p>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-green-600">STOP 到 TERMINATED</h3>
                        <p class="text-gray-700">在所有线程被成功中断且清理工作完成后，线程池会从 STOP 状态直接进入 TERMINATED 状态。需要注意的是，与 SHUTDOWN 路径不同，STOP 路径会跳过 TIDYING 状态，直接进入终止状态。</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```